<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 曾 -->
        <input type="text" v-model="newFiruts">
        <button @click='add'>增</button>
        <button @click='del'>删</button>
        <button @click='change'>替换</button>
        <ul>
            <li :key='index' v-for="(item,index) in list">{{item}}</li>
        </ul>


    </div>
</body>
<script src="../vue.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            newFiruts: '',
            list: ['apple', 'origin', 'banner']
        },
        methods: {
            add: function() {
                this.list.push(this.newFiruts)

            },
            del: function() {
                // 变异方法，修改原有数据
                this.list.pop()
            },
            change: function() {
                // slice,concat,filter:替换数组，生成新的数组，所以需要重新赋值
                this.list = this.list.slice(0, 2);

            }
        },
    })
    vm.$set(vm.list, 1, 'lele')
</script>

</html>